package org.jeecg.modules.nurse_user.service.impl;

import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.nurse_user.entity.NurseUser;
import org.jeecg.modules.nurse_user.entity.NurseUserFamily;
import org.jeecg.modules.nurse_user.entity.NurseUserAddr;
import org.jeecg.modules.nurse_user.entity.NurseUserIntegral;
import org.jeecg.modules.nurse_user.entity.NurseUserSpecial;
import org.jeecg.modules.nurse_user.mapper.NurseUserFamilyMapper;
import org.jeecg.modules.nurse_user.mapper.NurseUserAddrMapper;
import org.jeecg.modules.nurse_user.mapper.NurseUserIntegralMapper;
import org.jeecg.modules.nurse_user.mapper.NurseUserSpecialMapper;
import org.jeecg.modules.nurse_user.mapper.NurseUserMapper;
import org.jeecg.modules.nurse_user.service.INurseUserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 用户管理
 * @Author: jeecg-boot
 * @Date: 2024-06-09
 * @Version: V1.0
 */
@Service
public class NurseUserServiceImpl extends ServiceImpl<NurseUserMapper, NurseUser> implements INurseUserService {

    @Autowired
    private NurseUserMapper nurseUserMapper;
    @Autowired
    private NurseUserFamilyMapper nurseUserFamilyMapper;
    @Autowired
    private NurseUserAddrMapper nurseUserAddrMapper;
    @Autowired
    private NurseUserIntegralMapper nurseUserIntegralMapper;
    @Autowired
    private NurseUserSpecialMapper nurseUserSpecialMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delMain(String id) {
        nurseUserFamilyMapper.deleteByMainId(id);
        nurseUserAddrMapper.deleteByMainId(id);
        nurseUserIntegralMapper.deleteByMainId(id);
        nurseUserSpecialMapper.deleteByMainId(id);
        nurseUserMapper.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            nurseUserFamilyMapper.deleteByMainId(id.toString());
            nurseUserAddrMapper.deleteByMainId(id.toString());
            nurseUserIntegralMapper.deleteByMainId(id.toString());
            nurseUserSpecialMapper.deleteByMainId(id.toString());
            nurseUserMapper.deleteById(id);
        }
    }

    @Override
    public void clearUserInfo(String id, String openid) {
        //客户端删除用户信息
        if (oConvertUtils.isNotEmpty( id)) {
            nurseUserMapper.deleteNurseUser(id);
            nurseUserMapper.deleteNurseUserFamily(id);
        }
        //删除订单
        if (oConvertUtils.isNotEmpty( id)) {
            nurseUserMapper.deleteNurseUserOrdersDetail(id);
            nurseUserMapper.deleteNurseUserOrders(id);
            nurseUserMapper.deleteMedicationOrder(id);
        }
        //医护端删除用户信息
        if (oConvertUtils.isNotEmpty( openid)) {
            nurseUserMapper.deleteNurseUserProfile(openid);
            nurseUserMapper.deleteNurseNurses(openid);
        }

    }

}
